using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DefaultScrollListCreator : BaseScrollListCreator
{
    public override bool IsMoveBeforeDirection(Vector2 delta)
    {
        return false;
    }

    public override bool IsMoveNextDirection(Vector2 delta)
    {
        return false;
    }

    public override bool IsNeedCreateBefore()
    {
        return false;
    }

    public override bool IsNeedCreateNext()
    {
        return false;
    }

    public override void SetNormalizePosition(float normalize)
    {

    }

    public bool TryCreateItem(out RectTransform item, CreatorTool? tool)
    {
        item = PopItem();
        item.SetAsLastSibling();

        UpdateActiveList();

        m_lastItemChange(1);

        return true;
    }

    public override bool TryCreateBefore(out RectTransform item, CreatorTool? tool)
    {
        return TryCreateItem(out item, tool);
    }

    public override bool TryCreateNext(out RectTransform item, CreatorTool? tool)
    {
        return TryCreateItem(out item, tool);
    }

    public override bool TryGetItemByChildIndex(int childIndex, out RectTransform item)
    {
        item = null;

        if (childIndex >= activeList.Count || childIndex < 0)
            return false;

        item = activeList[childIndex];
        return true;
    }

    public override bool TryInsertItem(int childIndex, out RectTransform item)
    {
        item = null;

        if (childIndex >= activeList.Count || childIndex < 0)
            return false;

        item = PopItem();

        var unactivatedCount = GetUnactivatedCount(childIndex);
        var itemIndex = childIndex + unactivatedCount;

        item.SetSiblingIndex(itemIndex);

        UpdateActiveList();

        m_lastItemChange(1);

        return true;
    }

    public override void TryRemoveItem(int childIndex)
    {
        if (childIndex >= activeList.Count || childIndex < 0)
            return;

        RecycleItem(childIndex, activeList[childIndex]);
        m_lastItemChange(-1);

        UpdateActiveList();
    }
}